package com.young.fragments

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.young.fragments.databinding.ActivityMainBinding
import com.young.fragments.demo.activity_result_launcher_demo.ActivityResultLauncher1Activity
import com.young.fragments.demo.activity_result_launcher_demo.ActivityResultLauncherActivity
import com.young.fragments.demo.lazy_show_demo.LazyShowActivity
import com.young.fragments.demo.lazy_show_demo1.LazyShowActivity1
import com.young.fragments.demo.show_hide_demo.ShowHideDemoActivity
import com.young.fragments.demo.simple_jump_demo.Sample1Activity

class MainActivity : AppCompatActivity(), View.OnClickListener {

    private val mBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(mBinding.root)
        ViewCompat.setOnApplyWindowInsetsListener(mBinding.root) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        initClick()

    }

    override fun onClick(v: View?) {
        when (v) {
            mBinding.btnSample1 -> {
                val intent = Intent(this, Sample1Activity::class.java)
                startActivity(intent)
            }

            mBinding.btnSample2 -> {
                val intent = Intent(this, ShowHideDemoActivity::class.java)
                startActivity(intent)
            }

            mBinding.btnSample3 -> {
                val intent = Intent(this, LazyShowActivity::class.java)
                startActivity(intent)
            }

            mBinding.btnSample31 -> {
                val intent = Intent(this, com.young.fragments.demo.lazy_show_demo.LazyShowActivity1::class.java)
                startActivity(intent)
            }

            mBinding.btnSample4 -> {
                val intent = Intent(this, LazyShowActivity1::class.java)
                startActivity(intent)
            }

            mBinding.btnSample5 -> {
                val intent = Intent(this, ActivityResultLauncherActivity::class.java)
                startActivity(intent)
            }

            mBinding.btnSample6 -> {
                val intent = Intent(this, ActivityResultLauncher1Activity::class.java)
                startActivity(intent)
            }

        }
    }


    private fun initClick() {
        mBinding.btnSample1.setOnClickListener(this)
        mBinding.btnSample2.setOnClickListener(this)
        mBinding.btnSample3.setOnClickListener(this)
        mBinding.btnSample4.setOnClickListener(this)
        mBinding.btnSample5.setOnClickListener(this)
        mBinding.btnSample6.setOnClickListener(this)
        mBinding.btnSample31.setOnClickListener(this)
    }

}